from imageai.Detection.Custom import CustomVideoObjectDetection
import os
import datetime

#返回当前进程的工作目录。

def get_video(input_filepath):
    execution_path = os.getcwd()

    video_detector = CustomVideoObjectDetection()
    video_detector.setModelTypeAsYOLOv3()
    video_detector.setModelPath(
        r"D:\dProjects\newtest\face-dectction\ImageAI\examples\detection_model-ex-021--loss-0003.432.h5")  # download via https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/hololens-ex-60--loss-2.76.h5
    video_detector.setJsonPath(
        r"D:\dProjects\newtest\face-dectction\ImageAI\examples\detection_config.json")  # download via https://github.com/OlafenwaMoses/ImageAI/rel
    video_detector.loadModel()

    now_time = datetime.datetime.now().strftime('%Y%m%d') 
    video_path = video_detector.detectObjectsFromVideo(input_file_path=input_filepath,
                                            output_file_path=os.path.join(execution_path, now_time+"_detected"),
                                            frames_per_second=10,
                                            minimum_percentage_probability=50,
                                            log_progress=True)
    return video_path


